/*
fetch('https://match.yuanrenxue.cn/static/match/match15/main.wasm')
    .then(response =>
        response.arrayBuffer()
    )
    .then(bytes => WebAssembly.instantiate(bytes))
    .then(results => {
            const instance = results.instance;
            const window_q = instance.exports.encode;
            let t1 = parseInt(Date.parse(new Date()) / 1000 / 2);
            let t2 = parseInt(Date.parse(new Date()) / 1000 / 2 - Math.floor(Math.random() * (50) + 1));
            return window_q(t1, t2).toString() + '|' + t1 + '|' + t2;
        }
    )

 */

const fs = require('fs');
const path = require('path');

function run() {

    const wasmFilePath = path.resolve(__dirname, 'main.wasm');
    let module_ = new WebAssembly.Module(fs.readFileSync(wasmFilePath));
    const instance = new WebAssembly.Instance(module_);
    const window_q = instance.exports.encode;
    let t1 = parseInt(Date.parse(new Date()) / 1000 / 2);
    let t2 = parseInt(Date.parse(new Date()) / 1000 / 2 - Math.floor(Math.random() * (50) + 1));
    const result = window_q(t1, t2).toString() + '|' + t1 + '|' + t2;

    return result
}

// console.log(run());
